﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Earworm.Web.DBM;


namespace Earworm.Web.Registration
{
    public partial class ResetPass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnChangePass_Click(object sender, EventArgs e)
        {
            EarwormDataContext ear = new EarwormDataContext();
            var checkTemp = from ct in ear.Users
                            where ct.TempPassword == txtTempPass.Text & ct.Email == txtEmail.Text
                            select ct;

            if (checkTemp.Count() != 0)
            {
                User user = ear.Users.Single(u => u.Email == txtEmail.Text);
                user.TempPassword = "";
                user.Password = txtPass.Text;
                ear.SubmitChanges();

                lblMessage.Text = "Password has been reset";

            }
            else
            {
                lblMessage.Text = "Incorrect Email or temp password";

            }
        }
    }
}